<template>
  <view
    :class="[
      'item-dishe',
      info.count !== 0 ? 'emphasize' : '',
    ]"
  >
    <view :class="['count-dot',  info.count % 2 == 1 ? 'bounce-enter-active' : 'bounce-leave-active']" v-if="info.count"> {{ info.count }}</view>
    <view class="img" v-if="!props.noImageMode">
      <u-image :src="info.photo" width="100%" height="100rpx" mode="aspectFill"></u-image>
    </view>
    <view class="name line-clamp-1 text-ellipsis mt-3rpx">
      <text>
        {{ info.name }}
      </text>
      <view v-if="info.memberDiscount == '1'" class="ml-5rpx inline-flex bg-orange-300 px-3rpx py-2rpx rounded-sm">
        <text class="text-white text-sm"> 会员折扣 </text>
      </view>
    </view>
    <!-- 口味标签 -->
    <view class="spicy flex py-3rpx overflow-x-scroll">
      <view class="mr-5rpx tag" v-if="info.spicy">
        {{ info.spicy }}
      </view>
      <view class="mr-5rpx tag" v-if="info.texture">
        {{ info.texture }}
      </view>
      <view class="h-10rpx" v-if="!info.texture && !info.spicy">
        <!-- 都没有也占个位置 -->
      </view>
    </view>

    <!-- 禁忌人群 -->
    <view class="limt-population line-clamp-1 text-ellipsis">
      <text>禁忌人群: {{ info.tabooPopulation || "无" }} </text>
    </view>

    <!-- 价格 -->
    <view>
      <view class="price" v-if="info.memberDiscount == '1'">
        <text> ￥{{ info.price }}</text>
        <text class="line-through text-gray-400 ml-5rpx text-sm"> ￥{{ info.originalPrice }}</text>
      </view>
      <view class="price" v-else>
        <text> ￥{{ info.originalPrice }}</text>
      </view>
    </view>
  </view>
</template>
<script setup>
import { ref, watch } from "vue";

const props = defineProps({
  info: {
    type: Object,
    default: () => ({}),
  },
  noImageMode: {
    type: Boolean,
    default: true,
  },
});

const info = ref(props.info);

watch(
  () => props.info,
  (newVal) => {
    info.value = newVal;
  }
);
</script>
<style lang="scss" scoped>
.item-dishe {
  background-color: white;
  padding: 10rpx;
  display: flex;
  flex-direction: column;
  font-size: 10rpx;
  border-radius: 5rpx;
  position: relative;
  box-sizing: border-box;
  transition: 0.5s all;
  border: 1px solid transparent;
  box-shadow: 1px 1px 5px transparent;

  &:active {
    box-shadow: 3rpx 3rpx 6rpx var(--kui-color-theme);
  }

  &.emphasize {
    border: 1px solid var(--kui-color-theme);
    box-shadow: 3px 5px 8px var(--kui-color-theme-light);
  }

  .count-dot {
    position: absolute;
    top: 5rpx;
    right: 5rpx;
    background-color: rgba(255, 6, 6, 0.774);
    font-weight: bold;
    padding: 5rpx;
    border-radius: 50%;
    width: 8rpx;
    height: 8rpx;
    z-index: 3;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    box-shadow: 2px 2px 10px var(--kui-color-theme);
  }


  .img {
    width: auto;
    height: 100rpx;
    border-radius: 5rpx;
    overflow: hidden;
  }

  .name {
    font-size: 10rpx;
    font-weight: bold;
  }

  .limt-population {
    font-size: 8rpx;
    color: grey;
    box-sizing: border-box;
  }

  .price {
    font-size: 12rpx;
    color: #ff4949;
    font-weight: bold;
    margin-top: 5rpx;
  }

  // 弹动动画
  .bounce-enter-active {
    animation: bounce-in 0.5s;
  }

  .bounce-leave-active {
    animation: bounce-out 0.5s /*  reverse */;
  }

  @keyframes bounce-in {
    0% {
      transform: scale(0.8);
    }

    50% {
      transform: scale(1.2);
    }

    100% {
      transform: scale(1);
    }
  }

  @keyframes bounce-out {
    0% {
      transform: scale(0.8);
    }

    50% {
      transform: scale(1.2);
    }

    100% {
      transform: scale(1);
    }
  }
}
</style>
